import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'main',
    redirect: '/main'
  },
  {
    path: '/main',
    name: 'main',
    component: () => import('@/views/main.vue'),
    redirect: '/page1',
    children: [
      {
        path: '/page1',
        name: 'page1',
        component: () => import('@/pages/page1/index.vue'),

      },
      {
        path: '/page2',
        name: 'page2',
        component: () => import('@/pages/page2/index.vue'),

      },
      {
        path: '/page3',
        name: 'page3',
        component: () => import('@/pages/page3/index.vue'),

      },
      {
        path: '/page4',
        name: 'page4',
        component: () => import('@/pages/page4/index.vue'),

      },
    ]
  }
]

const router = new VueRouter({
  routes
})

// 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
export default router

